package springframework.bean;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * @author Cedric
 * @date 2021/11/30 09:41
 * @description 自定义拦截方法
 */
public class UserServiceInterceptor implements MethodInterceptor {
    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        long start = System.currentTimeMillis();
        try {
            return methodInvocation.proceed();
        } finally {
            System.out.println("监控开始-----");
            System.out.println("执行方法：" + methodInvocation.getMethod().getName());

            System.out.println("执行耗时：" + (System.currentTimeMillis() - start));
            System.out.println("监控结束-----");
        }
    }
}
